<template>
  <div class="FloorComponents">
    <!-- 轮播图 -->
    <van-swipe class="my-swipe" autoplay="2000" indicator-color="white">
      <van-swipe-item v-for="(banner, index) in bannerList" :key="index">
        <img class="swipe-img" :src="banner.picUrl" alt="" />
      </van-swipe-item>
    </van-swipe>
    <!-- 主体部分 -->
    <div class="contentList">
      <div
        class="contentItem"
        v-for="(categoryItem, index) in categoryItemList"
        :key="index"
      >
        <div class="content">
          <div class="content1">{{ categoryItem.category.name }}</div>
          <div class="content2">{{ categoryItem.category.frontName }}</div>
        </div>
        <div class="imgList">
          <div class="Item" @click="toDetail" v-for="(items) in categoryItem.itemList" :key="items.id">
            
            <img class="image" :src="items.listPicUrl" alt="" />
            <div class="content1">{{ items.name }}</div>
            <div class="content2">
              <span >{{
                items.finalPriceInfoVO.priceInfo.finalPrice?.prefix
              }}</span>
              ¥<span class="content2i1" v-if="!items.finalPriceInfoVO.priceInfo.finalPrice?.prefix">{{
                items.retailPrice
              }}</span>
              <span class="content2i1">{{
                items.finalPriceInfoVO.priceInfo.finalPrice?.price
              }}</span>
              <span class="content2i2"  v-if="items.finalPriceInfoVO.priceInfo.counterPrice"
                >￥{{ items.finalPriceInfoVO.priceInfo.counterPrice }}</span
              >
            </div>
            <span class="content3" v-if="items.finalPriceInfoVO.banner?.content" >{{
              items.finalPriceInfoVO.banner?.content
            }}</span>
            <div class="content4" v-if="items.finalPriceInfoVO.banner?.title">
              {{ items.finalPriceInfoVO.banner?.title }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { computed, defineComponent } from "vue";

export default defineComponent({
  name: "Floor",
});
</script>
<script lang="ts" setup>
  import { useRouter } from "vue-router";
  import {onMounted, watch, ref} from 'vue';
  import {useLivesStore} from '@/stores/live';
  import { storeToRefs } from "pinia";
  const livesStore = useLivesStore();

  let {bannerList, categoryItemList, categoryMain, itemLists} = storeToRefs(livesStore);
  // console.log(categoryItemList);
  // console.log(categoryMain.value[0].category.name);

  // watch(livesStore,()=>{
  //   console.log(livesStore);
  // })
  

  // onMounted(() => {
  //   livesStore.getLives();
  // })


  // 定义id数组
  const skuIdList = ref([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]);
  const skuIndex = ref(0); //定义下标
  const router = useRouter();

  //去详情页
  const toDetail = () => {
    // 随机下标
    skuIndex.value = Math.floor(
      Math.random() * (skuIdList.value.length - 1 - 0 + 1)
    );
    router.push(`/detail?skuId=${skuIdList.value[skuIndex.value]}`);
  };
  

onMounted(() => {
  livesStore.getLives();
});
</script>

<style lang="less" scoped>
.FloorComponents {
  width: 100%;
  // height: 2000px;
  .my-swipe {
    width: 100%;
    height: 180px;
    .swipe-img {
      width: 100%;
      height: 185px;
    }
  }
  .content {
    margin-top: 10px;
    text-align: center;
    .content1 {
      font-size: 16px;
    }
    .content2 {
      font-size: 12px;
      color: #999999;
      margin-top: 2px;
    }
  }
  .imgList {
    box-sizing: border-box;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    .Item {
      width: 49%;
      height: 310px;
      .image {
        width: 100%;
        height: 180px;
        border-radius: 5px;
      }
      .content1 {
        font-size: 15px;
        line-height: 20px;
      }
      .content2 {
        margin-top: 10px;
        font-size: 12px;
        color: #fa1e6e;
        font-weight: 700;
      }
      .content2i1 {
        font-size: 18px;
      }
      .content2i2 {
        color: #ccc;
        text-decoration: line-through;
      }
      .content3 {
        padding: 2px;
        background-color: red;
        border-radius: 8px;
        font-size: 12px;
        font-weight: bold;
        color: white;
      }
      .content4 {
        margin-left: 2px;
        font-size: 12px;
        font-weight: bold;
        color: red;
      }
    }
  }
}
</style>
